package com.yunfei.core.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.yunfei.common.frontend.consts.GlobMessageKeys;
import com.yunfei.core.utils.string.StringUtil;

import javax.sql.DataSource;

/**
 * @program: zntg_v1
 * @description:
 * @author: zhengyunfei
 * @create: 2018-11-01 15:14
 **/
public class DateSourceUtil {
    public static DataSource getDataSource(String webauthorize, String webauthorizeValue, String driverClass, String url, String user, String password) {
        DruidDataSource dataSource =null;
        if(!StringUtil.isNullOrEmpty(webauthorize)&&!StringUtil.isNullOrEmpty(webauthorizeValue)&&webauthorize.equals(webauthorizeValue)){
            Object bootstrap= Thread.currentThread().getContextClassLoader().getResource(GlobMessageKeys.BOOTSTRAP+GlobMessageKeys.PROPERTIES);
            if(!StringUtil.isNullOrEmpty(bootstrap)){
                dataSource= new DruidDataSource();
                dataSource.setDriverClassName(driverClass);
                dataSource.setUrl(url);
                dataSource.setUsername(user);
                dataSource.setPassword(password);
            }
        }
        return dataSource;
    }

}
